Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Returns the sin of a number using C code
- //as described in The Lua Programming Language, p242
- #include "lua.h"
- #include "lauxlib.h"
- #include "math.h"
- //function body
- static int l_sin (lua_State *L) {
- //double d = luaL_checknumber(L, 1); //get arg off the stack
- double d = lua_tonumber(L, 1); //get arg off the stack
- lua_pushnumber(L, sin(d)); //push result back onto the stack
- return 1; //return the number of results
- }
- /*
- static int dumbstuff (lua_State *L) {
- char dumb [] = "so dumb\n";
- lua_pushstring(L, dumb);
- return 1;
- }
- */
- //register the function with Lua
- static const struct luaL_Reg mylib [] = {
- {"mysin",l_sin},
- {NULL,NULL} /* this is a "sentinel" for the end of this list structure */
- };
- //this didn't work because lua was looking for luaopen_sintest in sintest.so
- //int luaopen_mylib (lua_State *L) {
- int luaopen_sintest (lua_State *L) {
- //luaL_register(L, "sintest",mylib);
- luaL_register(L, "hobjob",mylib); //type require "sintest" but use namespace "hobjob"
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement