LUA Registration function

Source: Internet
Author: User

#include <stdio.h>#include<math.h>#defineMax_color 255extern "C"{#include"Lua-5.2.2/src/lauxlib.h"#include"Lua-5.2.2/src/lualib.h"#include"lua-5.2.2/src/lstate.h"}/*parameter lua_state, the return value is the number of return values in the push result does not need to empty the stack, because there is a return value that represents the number of results, after the function returns LUA automatically clears the contents of the stack return results*/Static intL_sin (lua_state*L) {    DoubleD = Lual_checknumber (L,1);    Lua_pushnumber (L, sin (d)); return 1;}/*LUA registers the C library, passing the function names and corresponding functions pointers to LUA, and LUA uses table to store the information, which is also implemented by Lua's C libraries, which should be LUA global variables*/intMainintargcChar*argv[]) {Lua_state) O =lual_newstate ();///Quick and Dirty    //function into the stacklua_pushcfunction (L, L_sin); //assign to Global, pop a value from the stack and set it to global variable MysinLua_setglobal (L,"Mysin");    GetChar (); return 0;}

LUA Registration function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.