Comments (3)
using System;
using System.Runtime.InteropServices;
using KeraLua;
namespace ConsoleApp1
{
class Program
{
private static readonly uint LimitMemory = 4000;
private static uint _memory = 0;
private static uint MemoryInUse
{
get => _memory;
set
{
if (value > LimitMemory)
_lua.Error("Memory overflow");
_memory = value;
}
}
private static Lua _lua;
static void Main(string[] args)
{
LuaAlloc myAlloc = MyAlloc;
_lua = new Lua(myAlloc, IntPtr.Zero);
bool res = _lua.DoString("x = 10* 10");
res = _lua.DoString("x = 10* 10");
res = _lua.DoString("x = 10* 10");
res = _lua.DoString("x = 10* 10");
_lua.GetGlobal("x");
long x = _lua.ToInteger(-1);
}
private static IntPtr MyAlloc(IntPtr ud, IntPtr ptr, UIntPtr osize, UIntPtr nsize)
{
if (osize == nsize)
return ptr;
uint newSize = nsize.ToUInt32();
if (nsize == UIntPtr.Zero)
{
Marshal.FreeHGlobal(ptr);
MemoryInUse -= newSize;
return IntPtr.Zero;
}
if (ptr == IntPtr.Zero)
{
MemoryInUse += newSize;
return Marshal.AllocHGlobal((IntPtr) newSize);
}
return Marshal.ReAllocHGlobal(ptr, (IntPtr) newSize);
}
}
}
from keralua.
Fails when executed multiple times. "Process is terminating due to StackOverflowException."
using System;
using System.Runtime.InteropServices;
using KeraLua;
namespace ConsoleApp1
{
class Program
{
private static readonly uint LimitMemory = 400000;
private static uint _memory = 0;
private static uint MemoryInUse
{
get => _memory;
set
{
if (value > LimitMemory)
_lua.Error("Memory overflow");
_memory = value;
}
}
private static Lua _lua;
static void Main(string[] args)
{
LuaAlloc myAlloc = MyAlloc;
_lua = new Lua(myAlloc, IntPtr.Zero);
bool res = _lua.DoString("x = 10* 10");
for (int i = 0; i < 1000000; i++)
{
res = _lua.DoString("x = 10* 10");
}
_lua.GetGlobal("x");
long x = _lua.ToInteger(-1);
}
private static IntPtr MyAlloc(IntPtr ud, IntPtr ptr, UIntPtr osize, UIntPtr nsize)
{
if (osize == nsize)
return ptr;
uint newSize = nsize.ToUInt32();
if (nsize == UIntPtr.Zero)
{
Marshal.FreeHGlobal(ptr);
MemoryInUse -= newSize;
return IntPtr.Zero;
}
if (ptr == IntPtr.Zero)
{
MemoryInUse += newSize;
return Marshal.AllocHGlobal((IntPtr) newSize);
}
return Marshal.ReAllocHGlobal(ptr, (IntPtr) newSize);
}
}
}
from keralua.
That's a bummer 😕
Have no idea why. If you figure how to do it let us know 😉
from keralua.
Related Issues (20)
- Xamarin/Android: dlopen liblua53.so fails HOT 12
- Logo Copyright HOT 1
- Can't Build using VS 2019 Native Tools HOT 5
- 当lua代码出现死循环 我该怎么停止运行 这个时候button没有反应
- Fails to load lua53 assembly when building with Mono. HOT 9
- when reference by a classlib and build with any cpu (vs 2019) HOT 9
- State.NewLib State.SetFuncs: Attempted to read or write protected memory HOT 1
- Docs / Examples HOT 2
- How to use KeraLua.Lua.NewUserData correctly HOT 2
- Where is cyrillic support? HOT 6
- LuaSocket Debugger Support
- Build fails in Ubuntu/WSL using latest git HOT 1
- Linux library is not portable across distributions HOT 1
- Is it thread clean , when use as one tread one lua VM
- Can you open only some libraries? HOT 5
- Why data can be written at an offset memory location? HOT 1
- Can The State Be Set?
- Value returned from Lua.FromIntPtr should not be Disposable HOT 6
- DllNotFoundException with Unity
- NLua.Exceptions.LuaScriptException:“[string "chunk"]:3: attempt to index a nil value (global 'bit')” HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keralua.